package chunmap.example.crs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import chunmap.app.MapCtrl;
import chunmap.data.provider.LayerFactory;
import chunmap.example.BaseMap;
import chunmap.example.UiUtil;
import chunmap.model.crs.BLGrid;
import chunmap.model.crs.CoordinateRSystem;
import chunmap.model.crs.proj.Mercator;
import chunmap.model.crs.proj.ReProjOp;
import chunmap.view.layer.VectorLayer;

public class ProjTest extends BaseMap {
	public static void main(String[] args) {

		ProjTest me = new ProjTest();
		me.init();
	}

	@Override
	protected void addLayer(MapCtrl map) {
		String path1="D:\\Temp\\mapdata\\cntry02\\cntry02.shp";
		VectorLayer layer = (VectorLayer) LayerFactory.openShapeFile(path1);
		map.getLayerCollection().add(layer);
		
		VectorLayer grid = new BLGrid().createGrid();
        map.getLayerCollection().add(grid);
	}
	
	@Override
	protected void addButton(){
		super.addButton();
		
		UiUtil.addButton(frame,map,"墨卡托投影",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				CoordinateRSystem target = new CoordinateRSystem();
	            target.setProjection(new Mercator());

	            ReProjOp.changeMapCRS(map.getLayerCollection(), target);

	            map.fullView();
	            map.refreshMap();
			}
		});
		
		UiUtil.addButton(frame,map,"墨卡托反解",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ReProjOp.changeMapCRS(map.getLayerCollection(), CoordinateRSystem.Unknow);

	            map.fullView();
	            map.refreshMap();
			}
		});
	}
}